#include<sys/types.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<stdlib.h>

int main()
{
  int fd = open("fifo",O_WRONLY);
  if(fd < 0)
  {
    perror("open is error");
  }

  printf("this client:\n");
  char buff[64];
  int size = 1;
  while(size)
  {
    size = read(0,buff,sizeof(buff)-1);
    if(size > 0)
    {
      buff[size] = 0;
      write(fd,buff,strlen(buff));
    }
    else if(size < 0)
    {
      perror("read is error");
      exit(1);
    }
  }
  //fread(buff,1,strlen(buff),stdin);
  //int ch = 1;
  //int i = 0;
  //while(ch && ch != '\n')
  //{
  //  ch = getc(stdin);
  //  buff[i++] = ch;
  //  if(i == 63)
  //  {
  //    buff[63] = '\0';
  //    write(fd,buff,strlen(buff));
  //    memset(buff,0,64);
  //    i = 0;
  //  }
  //}
  //write(fd,buff,strlen(buff));
  return 0;
}
